<template>
  <div>
    <el-dialog
      title="分配角色"
      :visible.sync="shos"
      @before-close="guanbi"
      @close="guanbi"
    >
      <el-checkbox-group v-model="checkList">
        <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
          item.name
        }}</el-checkbox>
      </el-checkbox-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="guanbi">取 消</el-button>
        <el-button type="primary" @click="ok">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { role, getPermissionList } from '@/api/serring'
import { assignRoles } from '@/api/employess'
export default {
  name: 'VueAdminTemplateQuanxian',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    userid: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      id: '',
      shos: false,
      page: {
        page: 1,
        pagesize: 20
      },
      list: [],
      checkList: []
    }
  },
  watch: {
    userid: {
      handler(val) {
        this.id = val
      },
      immediate: true
    },
    show: {
      handler(vl) {
        console.log('变化')
        this.shos = vl
      },
      immediate: true
    }
  },
  mounted() {},
  created() {},
  methods: {
    async huoqu(id) {
      const res = await role(this.page)
      console.log(res.rows, 99999)
      this.list = res.rows
      // console.log(this.id)
      const re = await getPermissionList(id)
      console.log(re)
      this.checkList = re.roleIds
    },
    guanbi() {
      this.checkList = []
      this.shos = false
      this.$emit('update:show', false)
    },
    async ok() {
      await assignRoles({ id: this.id, roleIds: this.checkList })
      this.guanbi()
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
